package com.leetCode;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-23 00:27:21
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-23     张李鑫                     1.0         1.0 Version
 */
public class LengthOfLongestSubstring {
    /**
     * <p>
     * 给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度。
     * </p>
     *
     * @param s
     * @return
     * @Author zlx
     * @date 2021/9/23
     */
    public static int lengthOfLongestSubstring(String s) {
        if (null == s || s.length() == 0) {
            return 0;
        }
        HashSet<Character> set = new HashSet<>();
        char[] chars = s.toCharArray();
        int max = 0;
        int left = 0;
        for (int i = 0; i < chars.length; i++) {
            if (!set.contains(chars[i])) {
                set.add(chars[i]);
            } else {
                max = Math.max(max, set.size());
                while (left<i&&set.contains(chars[i])){
                    set.remove(chars[left]);
                    left++;
                }
                set.add(chars[i]);
            }
        }
        return Math.max(max,set.size());
    }

    public static void main(String[] args) {

        System.out.println((7-1)/2);
    }

}